/*
 * @Author: c
 * @Date: 2024-01-08 22:21:09
 * @LastEditTime: 2024-02-27 16:04:33
 * @LastEditors: c
 * @Description: 
 * @FilePath: \music-web-backend\src\core\music\video\entities\video.entity.ts
 * https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import { BasicEntity } from "src/common/entity/basic.entity";
import { VideoRate } from "src/common/entity/video.enity";
import { LangEnum } from "src/common/enums";
import { Column, Entity, JoinTable, ManyToMany, OneToMany, OneToOne, PrimaryGeneratedColumn } from "typeorm";
import { Artist } from "../../artist/entities/artist.entity";
import { Category } from "../../category/entities/category.entity";
import { Song } from "../../song/entities/song.entity";
import { User } from "src/core/system/user/entities/user.entity";
@Entity({
    name: 'video'
})
export class Video extends BasicEntity {

    @PrimaryGeneratedColumn("uuid")
    id: string;

    //唯一Code
    @Column({
        name: "asset_code",
        type: 'varchar',
        nullable: true,
        default: "",
        comment: "唯一Code"
    })
    assetCode: string;


    @Column({
        name: "object_name",
        type: 'varchar',
        nullable: true,
        default: "",
        comment: "原始视频存储名称"
    })
    objectName: string;

    //简介
    @Column({
        name: "introduce",
        type: 'varchar',
        default: "",
        length: 500,
        comment: "简介"
    })
    introduce: string;

    //语言缩写(zh)
    @Column({
        type: 'enum',
        enum: LangEnum,
        nullable: true,
        default: LangEnum.CN,
        comment: '语言（中文）'
    })
    lang: LangEnum;

    // //类别（国语流行）
    // @Column({
    //     name: "genreName",
    //     type: 'varchar',
    //     length: 10,
    //     comment: "类别全称"
    // })
    // genreName: string;

    //封面图
    @Column({
        name: "poster",
        type: 'varchar',
        nullable: true,
        comment: "封面图"
    })
    poster: string;

    //发行时间
    @Column({
        name: "original_release_date",
        type: 'timestamp',
        default: () => 'CURRENT_TIMESTAMP',
        comment: "发行时间"
    })
    originalReleaseDate: Date;

    //mv标题
    @Column({
        name: "title",
        type: 'varchar',
        comment: "mv标题"
    })
    title: string;

    //新增时间?
    @Column({
        name: "index_data_add_time",
        type: 'timestamp',
        default: () => 'CURRENT_TIMESTAMP',
        comment: "新增时间"
    })
    indexDataAddTime: Date;


    //播放总次数
    @Column({
        name: "playnum",
        type: 'int',
        default: 0,
        comment: "播放总次数"
    })
    playnum: number;


    //视频时长
    @Column({
        name: "duration",
        type: 'decimal',
        comment: "视频时长"
    })
    duration: number;

    //视频宽度
    @Column({
        name: "width",
        type: 'decimal',
        comment: "视频宽度"
    })
    width: number;

    //视频高度
    @Column({
        name: "height",
        type: 'decimal',
        comment: "视频高度"
    })
    height: number;


    //类别下面的子类别(摇滚-朋克)
    @ManyToMany(() => Category, cate => cate.videoList, {
        cascade: true,
    })
    @JoinTable({
        name: "video_cate", //生成的中间表名
        joinColumn: {
            name: "video_id", //生成的列名
            referencedColumnName: "id" //需要关联的列
        },
        inverseJoinColumn: {
            name: "cate_id", //需要被关联的生成的列名
            referencedColumnName: "id"//需要关联的列
        }
    })
    genre: Category[];

    //对应的歌曲
    @OneToOne(() => Song, song => song.video)
    song: Song;

    //歌手列表
    @ManyToMany(() => Artist, artist => artist.video)
    artistList: Artist[];
    
    //喜欢此歌曲的人
    @ManyToMany(() => User, user => user.favorVideoList, {
        cascade: true,
    })
    @JoinTable({
        name: "user_video_favor", //生成的中间表名
        joinColumn: {
            name: "video_id", //生成的列名
            referencedColumnName: "id" //需要关联的列
        },
        inverseJoinColumn: {
            name: "user_id", //需要被关联的生成的列名
            referencedColumnName: "id"//需要关联的列
        }
    })
    favoriteUsers: User[];

    // //所有分辨率
    // @OneToMany(() => VideoRate, rate => rate.videoList)
    // allRate: VideoRate[];
}

